export const userTypes = [
  {
    value: 'student',
    label: '学生'
  },
  {
    value: 'teacher',
    label: '老师'
  }
]

let lastId = 100

const uniqueId = () => lastId++

export const schools = [
  {
    id: uniqueId(),
    name: '海牛学校'
  }
]

export const buildings = [
  {
    id: uniqueId(),
    school: schools[0].id,
    schoolName: schools[0].name,
    type: 'student',
    name: '海牛学生楼一栋'
  },
  {
    id: uniqueId(),
    school: schools[0].id,
    schoolName: schools[0].name,
    type: 'student',
    name: '海牛学生楼二栋'
  },
  {
    id: uniqueId(),
    school: schools[0].id,
    schoolName: schools[0].name,
    type: 'teacher',
    name: '海牛教师楼'
  }
]
export const getBuilds = (type) => buildings.filter((b) => b.type == type)

export const floors = buildings.reduce((p, c) => {
  const temp = Array.from({ length: 6 }).map((_, idx) => ({
    id: uniqueId(),
    school: c.school,
    building: c.id,
    schoolName: c.schoolName,
    buildingName: c.name,
    floorNum: idx + 1,
    name: `${idx + 1}楼`
  }))
  return [...p, ...temp]
}, [])
export const getFloors = (type) => {
  const buildingIds = getBuilds(type).map((b) => b.id)
  return floors.filter((f) => buildingIds.includes(f.building))
}

export const rooms = floors.reduce((p, c) => {
  const temp = Array.from({ length: 6 }).map((_, idx) => ({
    id: uniqueId(),
    school: c.school,
    building: c.building,
    floor: c.id,
    floorNum: c.floorNum,
    roomNum: idx + 1,
    schoolName: c.schoolName,
    buildingName: c.buildingName,
    floorName: c.name,
    name: `${c.floorNum}${String(idx + 1).padStart(2, '0')}`
  }))
  return [...p, ...temp]
}, [])
export const getRooms = (type) => {
  const floorIds = getFloors(type).map((f) => f.id)
  return rooms.filter((r) => floorIds.includes(r.floor))
}

export const beds = rooms.reduce((p, c) => {
  const temp = Array.from({ length: 6 }).map((_, idx) => ({
    id: uniqueId(),
    school: c.school,
    building: c.building,
    floor: c.floor,
    floorNum: c.floorNum,
    room: c.id,
    roomNum: idx + 1,
    schoolName: c.schoolName,
    buildingName: c.buildingName,
    floorName: c.floorName,
    roomName: c.name,
    name: String(idx + 1),
    status: 'empty',
    type: 'man'
  }))
  return [...p, ...temp]
}, [])
export const getBeds = (type) => {
  const roomIds = getRooms(type).map((r) => r.id)
  return beds.filter((b) => roomIds.includes(b.room))
}

const studentBeds = getBeds('student')
export const students = Array.from({ length: 113 }).map((_, idx) => {
  const bed = studentBeds[idx]
  return {
    id: uniqueId(),
    no: `test${String(idx + 1).padStart(5, '0')}`,
    name: `海牛学生${idx + 1}`,
    sex: 'man',
    type: 'student',
    phone: '',
    avatar: '',
    schoolName: '海牛校区',
    enable: idx % 2 == 0,
    school: bed.school,
    building: bed.building,
    floor: bed.floor,
    room: bed.room,
    bed: bed.id
  }
})

const teacherBeds = getBeds('teacher')
export const teachers = Array.from({ length: 17 }).map((_, idx) => {
  const bed = teacherBeds[idx]
  return {
    id: uniqueId(),
    no: `teacher${String(idx + 1).padStart(5, '0')}`,
    name: `海牛教师${idx + 1}`,
    sex: 'man',
    type: 'teacher',
    phone: '',
    avatar: '',
    schoolName: '海牛校区',
    enable: idx % 2 == 0,
    school: bed.school,
    building: bed.building,
    floor: bed.floor,
    room: bed.room,
    bed: bed.id
  }
})

export const users = [...students, ...teachers]
